
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>菜单/传感器类别管理</h1>
	<ol class="breadcrumb">
		<li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>
				首页</a></li>
		<li><a href="#">类别管理</a></li>
		<li class="active">菜单/传感器类别管理</li>
	</ol>
</section>

<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box box-primary">
				<div class="box-body">
					<div class="row">
						<div class="col-sm-2">
							<div class="dataTables_length">
								<label>
									<select class="form-control input-sm pageSize" style="width:auto;">
										<option>10</option>
										<option>20</option>
										<option>30</option>
										<option>30</option>
										<option>40</option>
									</select>
									记录/页
								</label>
							</div>
						</div>
						<div class="col-sm-10">
							<div class="dataTables_filter" id="searchDiv">
								<input type="search" placeholder="请输入类别名称" title="类别名称" name="name"
									   class="form-control">
								<div class="btn-group">
									<button type="button" class="btn btn-primary" data-btn-type="search">查询</button>
								</div>
								<div class="btn-group">
									<button type="button" class="btn btn-default" data-btn-type="add">新增</button>
								</div>
							</div>
						</div>
					</div>


					<table id="check_table" class="table table-bordered table-striped table-hover" style="margin-bottom:20px;">
						<thead>
						<tr>
							<th name="id" style="display:none;">id</th>
							<th name="name">类别名称</th>
							<th name="valueNumber">属性值个数</th>
							<th name="">功能选项</th>
						</tr>
						</thead>
						<tbody></tbody>
					</table>
					<div class="paging"></div>
				</div>
			</div>
		</div>
	</div>
	</div>
</section>

<script>
	$(function() {

        var table=initTable("${basePath}/root/sensor/getSensorTypeList",
            $(".content #searchDiv"),
            $(".content table"),
            $(".content .pageSize"),
            $(".content .paging"));
        var param={
            htmlUrl:"${basePath}/function/manager/sensorType/sensorTypeForm",
            getEntityUrl:"${basePath}/root/sensor/getSensorTypeInfo",
            updateEntityUrl:"${basePath}/root/sensor/editSensorType",
            deleteEntityUrl:" ${basePath}/root/sensor/deleteSensorType",
            editTitle:"编辑传感器类别",
            addTitle:"添加传感器类别",
            addButton:$("[data-btn-type='add']"),
            table:$(".content table"),
            addCallback:function () {
                $("#sensorTypeForm .property").remove();
                $("#sensorTypeForm img").hide().attr("src","");
            },
            getEntityBefore:function (value) {
                $("#sensorTypeForm .property").remove();
            },
            getEntityCallback:function (value) {
                $("#sensorTypeForm img").attr("src","${basePath}/function/getSensorImage?path="+value.logo).show();
                AsyncGet("${basePath}/root/sensor/getPropertyBySensorTypeId",{id:value.id},function (data) {
                   data=data.data||data;
                    for(var i=1;i<=data.length;i++){
                        var id=$('<input class="property" type="hidden" name="propertyId'+i+'">');
                        id.val(data[i-1].id);
                        $("#sensorTypeForm").append(id);

                        var formGroup=$('<div class="form-group property"></div>');
                        var label=$('<label  class="col-sm-3 control-label"></label>');
                        label.text("属性值"+i+"名称");
                        var valueDiv=$('<div class="col-sm-9"></div>');
                        var input=$('<input type="text" class="form-control" name="propertyName'+i+'"/>');
                        input.val(data[i-1].name);
                        valueDiv.append(input);
                        formGroup.append(label).append(valueDiv);
                        $("#sensorTypeForm").append(formGroup);

                        var formGroup=$('<div class="form-group property"></div>');
                        var label=$('<label  class="col-sm-3 control-label"></label>');
                        label.text("属性值"+i+"别名");
                        var valueDiv=$('<div class="col-sm-9"></div>');
                        var input=$('<input type="text" class="form-control" name="propertyAlias'+i+'"/>');
                        input.val(data[i-1].alias);
                        valueDiv.append(input);
                        formGroup.append(label).append(valueDiv);
                        $("#sensorTypeForm").append(formGroup);

                        var formGroup=$('<div class="form-group property"></div>');
                        var label=$('<label  class="col-sm-3 control-label"></label>');
                        label.text("属性值"+i+"单位");
                        var valueDiv=$('<div class="col-sm-9"></div>');
                        var input=$('<input type="text" class="form-control" name="propertyUnit'+i+'"/>');
                        input.val(data[i-1].unit);
                        valueDiv.append(input);
                        formGroup.append(label).append(valueDiv);
                        $("#sensorTypeForm").append(formGroup);

                        var formGroup=$('<div class="form-group property"></div>');
                        var label=$('<label  class="col-sm-3 control-label"></label>');
                        label.text("属性值"+i+"图标");
                        var valueDiv=$('<div class="col-sm-9 file"></div>');
                        var input=$('<input type="text" class="form-control" name="icon'+i+'"/>');
                        input.val(data[i-1].icon);
                        var inputFile=$('<input type="file" accept="image/*" name="propertyFile'+i+'"/>');
                        valueDiv.append(input).append(inputFile);
                        var img=$('<img class="col-sm-offset-3">');
                        img.attr("src","${basePath}/function/getSensorImage?path="+data[i-1].icon).show();
                        formGroup.append(label).append(valueDiv).append(img);
                        $("#sensorTypeForm").append(formGroup);
                    }
                })
            }
		};
        EditEntity(param,table.search);

    });
</script>
